package com.helei.cloud.controller;

import com.helei.cloud.service.IPaymentHystrixservice;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author helei
 * @description OrderHystrixController
 * @date 2020/9/14 17:42
 */
@RestController
@EnableHystrix
@DefaultProperties(defaultFallback = "paymentInfo_TimeOut_Headler")
public class OrderHystrixController {
    @Resource
    private IPaymentHystrixservice paymentHystrixservice;

    @GetMapping("/consumer/aa")
    public String paymenInfo_OK(Integer id) {

        return paymentHystrixservice.paymenInfo_OK(id);
    }

    @GetMapping("/consumer/bb")
   /* @HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_Headler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "999999")
    })*/
    @HystrixCommand
    public String bb(Integer id) {
        int a = 10 / 0;
        return paymentHystrixservice.bb(id);
    }

    //全局fallback
    public String paymentInfo_TimeOut_Headler() {
        return "网络不加111122";
    }
}
